package com.hermes.action.login;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;

import com.hermes.common.action.BaseAction;
import com.hermes.common.util.LoginHelperUtil;
import com.hermes.common.util.ParameterParserUtil;


/**
* 
* 用户登出的跳转
* 
*/

public class LoginOutAction extends BaseAction{

		
	private static final long serialVersionUID = 1L;

	private static Logger log = Logger.getLogger(LoginOutAction.class);
	
	private boolean isHasLogined;
	
	private boolean result;


	public String execute() {
			
		String redirectUrl = ParameterParserUtil.getParameter("redirectUrl");
		log.error("-------------------------------");
		log.error("-------"+redirectUrl);
		//判断是否登录
		HttpServletRequest request = ServletActionContext.getRequest();
		LoginHelperUtil loginHelper = new LoginHelperUtil(request);
		if(loginHelper.hasLogined()){
			setHasLogined(true);
		}
	
		
		if(!isHasLogined){
			log.error("user not login");
			return SUCCESS;
		}
		
		if(loginHelper.quitLogin()){
			log.error("user-log-out-success");
		}
		
        HttpServletResponse response = ServletActionContext.getResponse();
        try {
			response.sendRedirect(redirectUrl);
		} catch (IOException e) {
			log.error("User-logout-error");
			e.printStackTrace();
		}
		
		return SUCCESS;
		
	}
	
	public boolean isHasLogined() {
			return isHasLogined;
	}
	public void setHasLogined(boolean isHasLogined) {
			this.isHasLogined = isHasLogined;
	}
			
}